package xubo.wangcaifeng.love.Utils

import org.apache.spark.sql.Row

object TU {
  /**
    * 过滤经纬度
    * .filter(t=>"long".nonEmpty && "long">= "73.66"  && "long"<= "135.05" && "lat".nonEmpty && "lat" >= "3.86" && "lat" <= "53.55")
    */
  val longandlat=
    """
      |long!="" and lat !="" and long >=73.66 and long <=135.05 and lat >= 3.86 and lat <= 53.55
    """.stripMargin
  val hasUserIdCondition = """
    |imei !="" or idfa !="" or mac !="" or androidid !="" or openudid != "" or
    |imeimd5 !="" or idfamd5 !="" or macmd5 !="" or androididmd5 !="" or openudidmd5 != "" or
    |imeisha1 !="" or idfasha1 !="" or macsha1 !="" or androididsha1 !="" or openudidsha1 != ""
  """.stripMargin
  def getUserId(row: Row):String={
    row match {
      case v if v.getAs[String]("imei").nonEmpty => "IM:"+v.getAs[String]("imei").toUpperCase()
      case v if v.getAs[String]("idfa").nonEmpty => "ID:"+v.getAs[String]("idfa").toUpperCase
      case v if v.getAs[String]("mac").nonEmpty => "MC:"+v.getAs[String]("mac").toUpperCase
      case v if v.getAs[String]("androidid").nonEmpty => "AD:"+v.getAs[String]("androidid").toUpperCase
      case v if v.getAs[String]("openudid").nonEmpty => "OU:"+v.getAs[String]("openudid").toUpperCase

      case v if v.getAs[String]("imeimd5").nonEmpty => "IMM:"+v.getAs[String]("imeimd5").toUpperCase
      case v if v.getAs[String]("idfamd5").nonEmpty => "IDM:"+v.getAs[String]("idfamd5").toUpperCase
      case v if v.getAs[String]("macmd5").nonEmpty => "MCM:"+v.getAs[String]("macmd5").toUpperCase
      case v if v.getAs[String]("androididmd5").nonEmpty => "ADM:"+v.getAs[String]("androididmd5").toUpperCase
      case v if v.getAs[String]("openudidmd5").nonEmpty => "OUM:"+v.getAs[String]("openudidmd5").toUpperCase

      case v if v.getAs[String]("imeisha1").nonEmpty => "IMS:"+v.getAs[String]("imeisha1").toUpperCase
      case v if v.getAs[String]("idfasha1").nonEmpty => "IDS:"+v.getAs[String]("idfasha1").toUpperCase
      case v if v.getAs[String]("macsha1").nonEmpty => "MCS:"+v.getAs[String]("macsha1").toUpperCase
      case v if v.getAs[String]("androididsha1").nonEmpty => "ADS:"+v.getAs[String]("androididsha1").toUpperCase
      case v if v.getAs[String]("openudidsha1").nonEmpty => "OUS:"+v.getAs[String]("openudidsha1").toUpperCase
    }
  }

}
